Repository navigation
Add a user ssh-agent service that survives keyring restarts - #114
Merged
Merged
Conversation
SSH_AUTH_SOCK pointed at the gnome-keyring socket. After the keyring daemon restarted without its SSH component, that socket refused connections and long-lived processes such as herdr kept the stale path, so ssh asked for a passphrase on every connection. Ubuntu 22.04 has no gcr-ssh-agent to replace it. Track a systemd user service for ssh-agent on a fixed socket, the environment.d entry that exports it, a fallback in .bashrc.d/envrc for shells that inherited a dead agent, and AddKeysToAgent in ssh/config. The service is not enabled by --update.
diegoferigo
marked this pull request as ready for review
November 26, 2026 17:15
The environment.d entry set SSH_AUTH_SOCK on every machine that received the files, but nothing enabled the unit. The distro launchers start an agent only when the variable is unset, so a machine without the enabled unit ended up with no agent. The envrc fallback also aborted shells running under set -e, because ssh-add -l exits 1 or 2. Drop the environment.d entry and let the unit export the variable once the agent runs. Capture the ssh-add status without tripping set -e, restart the unit always, and fix the AGENTS.md cross-reference and the file tree.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What change is being made
Track a systemd user service that runs
ssh-agenton$XDG_RUNTIME_DIR/ssh-agent-user.socketand exportsSSH_AUTH_SOCKinto the user manager once it runs, a fallback in.bashrc.d/envrcfor shells that inherited a dead agent, andAddKeysToAgent yesin.ssh/config.AGENTS.mddocuments it in a new "SSH agent" section.Why this change is being made
SSH_AUTH_SOCKpointed at the gnome-keyring socket. After the keyring daemon restarted without its SSH component, that socket refused connections. herdr, a long-lived process, kept using it, sosshasked for the passphrase on every connection. Ubuntu 22.04 has nogcr-ssh-agent, so a desktop-independent agent on a fixed path is the portable choice.The unit is not socket-activated because
ssh-agentcannot take a socket from systemd. It has its own name so it does not shadow the packagedssh-agent.service.--updateonly deploys the files: enable it once per machine withsystemctl --user enable --now ssh-agent-user.service. Doing that from--updateis left for a follow-up.Tested
pixi run -q hooks: all hooks passed.pixi run -q test: 391 passed (after the review fixes too).envrcfallback in a cleanenv -ishell: a deadSSH_AUTH_SOCKand an unset one switch to the socket, a live other agent is kept.ssh-addloads the key andssh wsworks inBatchMode.